var prefix = "/admin/role";

function setPerm(roleId) {
  var url = '/pages/sysadm/role/rolePerm?roleId=' + roleId;
  $.modal.open("分配权限", url);
}

$(function () {
  //toolbar权限控制
  toolBarPermission()
  var editFlag = permissions.sys_role_edit
  var delFlag = permissions.sys_role_del
  var permFlag = permissions.sys_role_perm
  var options = {
    url: prefix + "/page",
    updateUrl: "/pages/sysadm/role/roleEdit",
    removeUrl: prefix + "/{id}",
    exportUrl: prefix + "/export",
    sortName: "roleName",
    sortOrder: "asc",
    modalName: "角色",
    // onSort: function (name, order) {
    //   console.log('3333333333333', name, order)
    //   /*********第3步，刷新排序字段和排序方法，完成************/
    //   // $('#table').bootstrapTable('refreshOptions', {
    //   //   sortName: name,
    //   //   sortOrder: order
    //   // });
    // },
    columns: [
      {
        title: "序号",
        formatter: function (value, row, index) {
          return $.table.serialNumber(index);
        }
      },
      {
        field: 'roleName',
        title: '角色名称',
        formatter: function (value, row, index) {
          return '<a href="javascript:$.operate.view(' + "'" + row.roleId + "'" + ')">' + value + '</a>';
        }
      },
      {
        field: 'roleCode',
        title: '角色标识'
      },
      {
        field: 'dsType',
        title: '数据权限类型',
        formatter: function (value, row, index) {
          if ('0' == value) {
            return '全部';
          }
          if ('2' == value) {
            return '本级及子级';
          }
          if ('3' == value) {
            return '本级';
          }
          if ('1' == value) {
            return '自定义';
          }
        }
      },
      {
        field: 'createTime',
        title: '创建时间',
        sortable: true
      },
      {
        title: '操作',
        formatter: function (value, row, index) {
          var actions = [];
          if (editFlag) {
            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.roleId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
          }
          if (delFlag) {
            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.roleId + '\')"><i class="fa fa-remove"></i>删除</a> ');
          }
          if (permFlag) {
            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="setPerm(\'' + row.roleId + '\')"><i class="fa fa-user"></i>分配权限</a> ');
          }
          return actions.join('');
        }
      }]
  };
  $.table.init(options);
});